<?php

/**
 * This is the model class for table "{{setting}}".
 *
 * The followings are the available columns in table '{{setting}}':
 * @property integer $id
 * @property string $category
 * @property string $key
 * @property string $value
 */
class Setting extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Setting the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{setting}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('key, value', 'required'),
			array('category', 'length', 'max'=>64),
			array('key', 'length', 'max'=>255),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, category, key, value', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'category' => 'Категория',
			'key' => 'Ключ',
			'value' => 'Значение',
		);
	}

    
    public function getThemes()                  //метод возвращает список всех тем в дирректории themes
    {
        $themepath = Yii::getPathOfAlias('webroot').'/data/themes';                      //путь до какталога с темами
        $arrthemes = scandir($themepath);                                                //получаем массив с названиями тем
        $arrthemes = array_slice($arrthemes, 2);                                          //удаляем 2 точки вначале массива 
        
        $newarr = array();
        $newarr[0] = '';                                    //первый элемент списка по умолчанию
        foreach($arrthemes as $k=>$v)
        {
            $newarr[$k+1] = $v;
        }
       
        return $newarr;                                 
    }
   
   
    public function getCurrenttheme()               //Метод возвращает текущую тему
    {
        $config = array();
        $config = include Yii::getPathOfAlias('application').'/config/incfrontconfig.php';
              return $config['theme'];
    }
    
    
    
}